let vm = new Vue({
    el:'.main-content',  //选中整个main
    data:{
        //apps:{},//初始化对象     vue建议声明对象同时进行初始化，避免undefinded
        isActive:true,  //显示页面
        page:{},//页面信息
        app:{}
    },
    methods:{
        selectAll:function (start=1,pageSize=5) {
            axios({
                url:'/guguanjia/manager/app//selectPage',   //相对路径同样受到base标签影响
                params:{
                    start:start,
                    pageSize:pageSize
                }
            }).then(
                response=>{  //省略function关键字  自动传递上下文中的this
                    //this.apps = response.data.obj.list;
                    this.page = response.data.obj
                }
            ).catch(error=>{
                console.log(error.message);
            })
        },
        toUpdate:function (app) {
            layer.obj = app;
            layer.open({
                type: 2,
                title: '更新',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area : ['800px' , '520px'],
                content: 'app/update.html',
                end: ()=>{
                    // layer.msg("更新完成")
                    this.selectAll();//刷新页面
                }
            });
        },
        deleteAppVersionById:function (id) {
            layer.confirm('确认是否要删除？', {
                btn: ['是','否'] //按钮
            }, ()=>{
                axios({
                    url: `/guguanjia/manager/app/deleteAppVersionById`,
                    method:"put",
                    data:{
                        id:id
                    }
                }).then(
                    (result)=>{
                        if (result.data.success){
                            layer.msg("删除成功");
                            this.selectAll();
                        }else {
                            layer.msg("删除失败");
                        }
                    }
                ).catch((error)=>{
                    layer.msg("删除失败");
                })
            }, function(){
                layer.msg("取消")
            });
        },
        insert:function(){
            axios.post("/guguanjia/manager/app/insertAppVersion",this.app).then(
                (result)=>{
                    if (result.data.success){
                        //切换前先清空数据
                        this.app={};
                        //插入成功，切换到列表页面
                        this.isActive=!this.isActive;
                        layer.msg("插入成功！")
                    }
                }
            ).catch((error)=>{
                layer.msg(error.message)
            })
        },
        changeShow:function () {
            this.isActive=!this.isActive;
            // console.log(this.isActive);
        },
        todetil:function (app) {
            layer.obj = app;
            layer.open({
                type: 2,
                title: '更新',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area : ['800px' , '520px'],
                content: 'app/detail.html',
            });
        },
    },
    created:function () {
        this.selectAll();
    }
});